<?php
/**
 * Created by PhpStorm.
 * User: 47557
 * Date: 2017/4/12
 * Time: 20:06
 */

namespace app\db\controller;


use think\config\driver\Json;
use think\Controller;
use think\Db;
use think\Exception;
use think\Request;

class Usercontrol extends Dbcommoncontrol
{
   protected $DbName='UserInf';

   function UserLogin()
   {
     try{
         $id=$_POST["id"];
         $pwd=$_POST["pwd"];
         $user=DB::table('UserInf')
         ->where('u_loginid',$id)->where('U_pwd',$pwd)->field('U_LoginId,U_Pwd',true)->find();
         if($user==null)
             return  "id||pwd error";
         return Json($user);//登陆成功返回信息
     }
     catch (Exception $ECE)
       {
           return $ECE->getMessage();
       }
   }
   function GetUserPlan()
   {
       try
       {
           $u_id=$_POST["u_id"];
           if($u_id!=null) {
               $record=Db::table('PlanInf')->where('U_Id', '=', $u_id)->select();
               if($record==null)
                   return "no plan";
               return json_encode($record);
           }
       }
       catch (Exception  $ex)
       {
           return $ex->getMessage();
       }

   }
   function AddPlanid()
   {
       try{
           $p_id=$_POST["plan_id"];
           $u_id=$_POST["user_id"];
           $user=DB::table('UserInf')
               ->where('U_Id',$u_id)->find();
           if($user==null)
               return  "error u_id";
           $user["U_PlanId"]=$p_id;
           $this->Getnew()->update($user);
           return "true";
       }
       catch (Exception $ECE)
       {
           return $ECE->getMessage();
       }
   }
   function OverToday()
   {
       try{
           $u_id=$_POST['u_id'];
           $p_id=$_POST['p_id'];
           //更新用户表信息
           $user=DB::table('UserInf')
               ->where('U_Id',$u_id)->find();
           $user['U_WorkDays']++;
           DB::table('UserInf')->update($user);
           //更新计划表信息
           $plan=Db::table('PlanInf')
               ->where('P_Id','=',$p_id)
               ->find();
           $plan['P_OverDay']++;
           DB::table('PlanInf')->update($plan);
           return "true";
       }
       catch (Exception $ECE)
       {
           return $ECE->getMessage();
       }
   }
   function SetPlanEmpty()
    {
        try
        {
            $u_id=$_POST['u_id'];
            $user=Db::table($this->DbName)->where('u_id','=',$u_id)->find();
            $user['U_PlanId']="";
            return Db::table($this->DbName)->update($user);
        }
        catch (Exception  $ex)
        {
            return "false";
        }
    }
    function IdGetUser()
    {
        $u_id=$_POST['u_id'];
        $user=Db::table($this->DbName)->where('u_id','=',$u_id)->find();
        return json($user);
    }
}